package com.ssm.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.annotation.DataSource;
import com.ssm.entity.MBaseCustomersPO;
import com.ssm.enums.DataSourceEnum;
import com.ssm.mapper.MBaseCustomersMapper;
import com.ssm.service.MBaseCustomersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * @author zchcpywin10
 */
@Service
public class MBaseCustomersServiceImpl extends ServiceImpl<MBaseCustomersMapper, MBaseCustomersPO> implements MBaseCustomersService {
  @Autowired
  MBaseCustomersMapper mBaseCustomersMapper;
  @Override
  @DataSource(DataSourceEnum.DB3)
  public int updateBatch(List<MBaseCustomersPO> list) {
    return baseMapper.updateBatch(list);
  }
  @Override
  @DataSource(DataSourceEnum.DB3)
  public int updateBatchSelective(List<MBaseCustomersPO> list) {
    return baseMapper.updateBatchSelective(list);
  }
  @Override
  @DataSource(DataSourceEnum.DB3)
  public int batchInsert(List<MBaseCustomersPO> list) {
    return baseMapper.batchInsert(list);
  }
  @Override
  @DataSource(DataSourceEnum.DB3)
  public int insertOrUpdate(MBaseCustomersPO record) {
    System.out.println("record = " + record);
    return baseMapper.insertOrUpdate(record);
  }
  @Override
  @DataSource(DataSourceEnum.DB3)
  public int insertOrUpdateSelective(MBaseCustomersPO record) {
    return baseMapper.insertOrUpdateSelective(record);
  }
  @Override
  @DataSource(DataSourceEnum.DB3)
  public List<MBaseCustomersPO> iPageSelect(IPage<MBaseCustomersPO> myPage) {
    System.out.println("myPage = " + myPage);
    return mBaseCustomersMapper.iPageSelect(myPage);
  }
  @DataSource(DataSourceEnum.DB3)
  @Override
  public List<MBaseCustomersPO> getPageTest(IPage<MBaseCustomersPO> page) {
    //使用分页插件
    PageHelper.startPage(2, 3);
    List<MBaseCustomersPO> mBaseCustomersPOList = mBaseCustomersMapper.getPageTest();
    PageInfo<MBaseCustomersPO> infos = new PageInfo<>(mBaseCustomersPOList);
    List<MBaseCustomersPO> mBaseCustomersPOListPage = infos.getList();
    return mBaseCustomersPOList;
  }
  @Override
  @DataSource(DataSourceEnum.DB3)
  public List<MBaseCustomersPO> list(Wrapper<MBaseCustomersPO> queryWrapper) {
    return super.list(queryWrapper);
  }
}
